package com.flying.scorer.score.equity.multi;

import com.flying.refdata.model.equity.EquityInfo;
import com.flying.refdata.model.equity.MarketData;
import com.flying.refdata.model.equity.QuarterlyReport;
import com.flying.refdata.service.MarketDataService;
import com.flying.refdata.service.ReportService;
import com.flying.scorer.score.ScoreException;
import com.flying.scorer.score.equity.AbstractEquityScorer;
import com.flying.utils.bean.BeanUtil;

public class ROEPBEquityScorer extends AbstractEquityScorer {

    private MarketDataService marketDataService;
    private ReportService reportService;

    public ROEPBEquityScorer(MarketDataService marketDataService, ReportService reportService) {
        this.marketDataService = marketDataService;
        this.reportService = reportService;
    }

    @Override
    public double score(int date, EquityInfo info) throws ScoreException {
        MarketData md = marketDataService.getMarketData(info, date);
        if (md == null)
            throw new ScoreException("Can't find the market data. date:" + date + "equity info:" + BeanUtil.describe(info));
        QuarterlyReport qr = reportService.getLatestQuarterlyReport(info, date);
        if (qr == null)
            throw new ScoreException("Can't find the quarterly report. date:" + date + "equity info:" + BeanUtil.describe(info));

        double ratio = qr.getNetAssetROE() / md.getPb();
        if (ratio < 2) return 0;
        else if (ratio < 3) return 3;
        else if (ratio < 4) return 6;
        else if (ratio < 5) return 9;
        else if (ratio < 6) return 12;
        else if (ratio < 7) return 15;
        else if (ratio < 8) return 18;
        else return 20;
    }
}
